package idv.arthur.CommonUtilTest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

import com.cht.sys.CommonUtil;
import com.cht.sys.LDAP;

public class CommonUtilTest {

	static private String url = "http://10.80.71.72:8056/UtilWeb/";
	
	public static void main(String[] args) throws Exception {
		System.out.println(CommonUtil.getDutyCount("830029"));
		
		/*ArrayList testArrayList = CommonUtil.getDutyList("830029");
		
		for(int i=0;i<testArrayList.size();i++) {
			System.out.println((String)testArrayList.get(i));
		}
		*/
	}
	
	private static String queryServlet(String method,String params) throws Exception {
		InputStream ins = null;
		String res = "";
		try {
			
			URL gwtServlet = new URL(url+method+params);
			HttpURLConnection servletConnection = (HttpURLConnection) gwtServlet.openConnection();
			ins = servletConnection.getInputStream();

			res = convertStreamToString(ins);
			
			if ( res.equalsIgnoreCase("") ) {
				res = null;	
			}	
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			if (ins != null) { try { ins.close(); } catch (IOException e) { e.printStackTrace(); } }
		}
		return res;
	}
	//轉換inputStream 為 字串
		private static String convertStreamToString(InputStream is) throws IOException {
			if (is != null) {
				Writer writer = new StringWriter();

				char[] buffer = new char[1024];
				try {
					Reader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
					int n;
					while ((n = reader.read(buffer)) != -1) {
						writer.write(buffer, 0, n);
					}
				} finally { is.close(); }
				return writer.toString();
			} else { return ""; }
		}
}
